//package com.yuan.spring.mvc;
//
//import org.springframework.http.HttpStatus;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//
///**
// * 错误信息提示
// * 浏览器请求时可以进行错误跳转  但是当进行post 请求是则不能返回希望的错误提示
// * ?为什么spring boot 要加这么一个异常处理类
// * Created by 袁恩光 on 2017/5/27.
// */
//@RestController
//public class MyErrorPage implements ErrorController {
//
//    private static final String ERROR_PATH = "/error";
//
//    @RequestMapping(value = ERROR_PATH)
//    public ResponseMsg handleError(HttpServletRequest request) {
//        RequestAttributes requestAttributes = new ServletRequestAttributes(request);
//        Object objectMsg = requestAttributes.getAttribute("javax.servlet.error.message", RequestAttributes.SCOPE_REQUEST);
//        HttpStatus status = getStatus(request);
//        String msg;
//        switch (status) {
//            case NOT_FOUND:
//                msg = "请求链接不正确";
//                break;
//            case INTERNAL_SERVER_ERROR:
//                msg = "内部错误";
//                break;
//            default:
//                msg = null == objectMsg ? "内部错误" : "请求参数不正确:" + objectMsg.toString();
//                break;
//        }
//        return new ResponseMsg("0", "", msg);
//    }
//
//    @Override
//    public String getErrorPath() {
//        return ERROR_PATH;
//    }
//
//    private HttpStatus getStatus(HttpServletRequest request) {
//        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
//        if (statusCode == null) {
//            return HttpStatus.INTERNAL_SERVER_ERROR;
//        }
//        try {
//            return HttpStatus.valueOf(statusCode);
//        } catch (Exception ex) {
//            return HttpStatus.INTERNAL_SERVER_ERROR;
//        }
//    }
//
//}
